﻿
--drop procedure [PomPropertySave]
alter PROCEDURE [PomPropertySave]
(
	@pAddressLine1 VARCHAR(60),
	@pAddressLine2 VARCHAR(60),
	@pCity VARCHAR(60),
	@pCounty VARCHAR(60),
	@pPostcode VARCHAR(9),
	@pAddressID INT,
	@pPomplingCustomerID VARCHAR(32),
	@pPropIsLet BIT
)

AS
BEGIN
	SET NOCOUNT ON;
	declare @PropSaleType VARCHAR(5)
	IF @pPropIsLet = 0 SET @PropSaleType = 'Let' ELSE set @PropSaleType = 'For Sale'

	
	if @pAddressID < 1
	BEGIN		
		INSERT INTO PomPomplingAddresses ([AddressLine1],[AddressLine2],[City],[County],[Postcode], [AddressType], [PomplingCustomerID]) 
			VALUES (@pAddressLine1, @pAddressLine2, @pCity, @pCounty, @pPostcode, @PropSaleType, @pPomplingCustomerID);
		SET @pAddressID = SCOPE_IDENTITY();
	END	ELSE 
	BEGIN
		UPDATE PomPomplingAddresses
		SET [AddressLine1] = @pAddressLine1,
		[AddressLine2] = @pAddressLine2,
		[City] = @pCity,
		[County] = @pCounty,
		[Postcode] = @pPostcode,
		[AddressType] = @PropSaleType
		WHERE PomplingAddressID = @pAddressID
	END
	SELECT @pAddressID
END

